package com.eliysha.bible;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.NetworkInfo.State;

public class Asset {
	public static ProgressDialog dialog;
	public static boolean isConnected(Activity activity) {
		  ConnectivityManager connectivityManager = (ConnectivityManager)  activity.getSystemService(Context.CONNECTIVITY_SERVICE);
		  NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
		  if (networkInfo != null) {
		    // System.out.println(networkInfo.getTypeName()); // mobile ou WIFI
		    State networkState = networkInfo.getState();
		    if (networkState.compareTo(State.CONNECTED) == 0) {
		      return true;
		    }
		  }
		  return false;
	}
	
	public static void showAlert(String msg, Activity activity){
		// prepare the alert box
        AlertDialog.Builder alertbox = new AlertDialog.Builder(activity);

        // set the message to display
        alertbox.setMessage(msg);

        // add a neutral button to the alert box and assign a click listener
        alertbox.setNeutralButton("Ok", new DialogInterface.OnClickListener() {

            // click listener on the alert box
            public void onClick(DialogInterface arg0, int arg1) {
            }
        });

        // show it
        alertbox.show();
	}
	
	public static void showProgressBar(Activity activity){
		// prepare the dialog box
        dialog = new ProgressDialog(activity);

        // make the progress bar cancelable
        dialog.setCancelable(true);

        // set a message text
        dialog.setMessage("Loading...");

        // show it
        dialog.show();
	}
	public static void hideProgressBar(Activity activity){
		dialog.hide();
		dialog.dismiss();
	}
}
